import sys
sys.path.append("../")
from frameworks.cores.LoadClass import *
from frameworks.utils.RedisUtil import *
import json

class LoadModelController:
    def __init__(self):
        self.redis = RedisUtil()
        self.modellist = [
            {"name":"bigstock","file":"controller.BigStockModelController","controller":"BigStockModelController"},
            {"name": "haszhangting", "file": "controller.ActionStockModelController", "controller": "ActionStockModelController"}
        ]
        self.load = LoadClass()

    def loadModel(self):
        args = {"func":"calcModel"}
        for option in self.modellist:
            rs = self.load.load(option["file"], option["controller"], args)
            self.redis.setArray(option["name"], rs)

    def getModelData(self):
        rs = {}
        for option in self.modellist:
            alldata = []
            data = self.redis.getArray(option["name"])
            for line in data:
                obj = json.loads(line.replace("'","\""))
                alldata.append(obj)
            rs[option["name"]] = alldata
        return rs